﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YLW.Plat.Jhfw.HL7V3.XSDModels.PRPA_IN410001UV_Mzyy;
using YLW.Plat.Jhfw.Model.JhfwMzyy;

namespace YLW.Plat.Jhfw.HL7V3.V3Message
{
    public class V3_PRPA_IN410001UV_Mzyy
    {
        public static string OutPatientAppointStatusInfoAdd(AddJhfwMzyyIn jsonData, string id_extension, string sender_name, string receiver_name)
        {
            string hl7Xml = string.Empty;

            if (jsonData == null)
            {
                return hl7Xml;
            }

            //根据XML XSD构建HL7 XML消息格式

            //创建根对象
            var xmlRoot = new PRPA_IN410001UV
            {
                ITSVersion = "XML_1.0",
                id1 = new id1 { root = "2.16.156.10011.2.5.1.1", extension = id_extension },
                creationTime = new creationTime { value = DateTime.Now.ToString("yyyyMMddHHmmss") },
                interactionId = new interactionId { root = "2.16.156.10011.2.5.1.2", extension = "PRPA_IN410001UV" },
                processingCode = new processingCode { code = "P" },
                processingModeCode = new processingModeCode(),
                acceptAckCode = new acceptAckCode { code = "AL" },
                receiver = new receiver
                {
                    typeCode = "RCV",
                    device = new device
                    {
                        classCode = "DEV",
                        determinerCode = "INSTANCE",
                        id1 = new id1
                        {
                            item = new item
                            {
                                root = "2.16.156.10011.2.5.1.3",
                                extension = receiver_name
                            }
                        }
                    }
                },
                sender = new sender
                {
                    typeCode = "SND",
                    device = new device
                    {
                        classCode = "DEV",
                        determinerCode = "INSTANCE",
                        id1 = new id1
                        {
                            item = new item
                            {
                                root = "2.16.156.10011.2.5.1.3",
                                extension = sender_name
                            }
                        }
                    }
                },
                controlActProcess = new controlActProcess
                {
                    classCode = "INFO",
                    moodCode = "APT",
                    subject = new subject
                    {
                        typeCode = "SUBJ",
                        encounterAppointment = new encounterAppointment
                        {
                            id1 = new id1
                            {
                                item = new item { root = "2.16.156.10011.2.5.1.29", extension = jsonData.yyid }
                            },
                            code = new code(),
                            statusCode = new statusCode { code = "active" },
                            effectiveTime = new effectiveTime
                            {
                                low1 = new low1 { value = jsonData.yyjzsj }
                            },
                            subject = new subject
                            {
                                patient = new patient
                                {
                                    classCode = "PAT",
                                    id1 = new id1
                                    {
                                        item = new item { root = "2.16.156.10011.2.5.1.4", extension = jsonData.mrn }
                                    },
                                    patientPerson = new patientPerson
                                    {
                                        id1 = new id1
                                        {
                                            item = new item { root = "2.16.156.10011.1.3", extension = jsonData.pcid }
                                        },
                                        name = new name
                                        {
                                            item = new item
                                            {
                                                part = new part
                                                {
                                                    value = jsonData.pname
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            reusableDevice = new reusableDevice
                            {
                                time = new low
                                {
                                    low1 = new low1
                                    {
                                        value = jsonData.yyjzsj
                                    }
                                },
                                assignedDevice = new assignedDevice
                                {
                                    classCode = "ASSIGNED",
                                    id1 = new id1 { root = "2.16.156.10011.2.5.1.3", extension = jsonData.yyid },
                                    code = new code
                                    {
                                        code1 = jsonData.yyztdm,
                                        codeSystem = "2.16.156.10011.2.5.1.30",
                                        codeSystemName = "门诊预约状态代码表",
                                        displayName = new displayName
                                        {
                                            value = jsonData.yyztmc
                                        }
                                    }
                                }
                            },
                            performer = new performer
                            {
                                typeCode = "PRF",
                                time = new low
                                {
                                    low1 = new low1
                                    {
                                        value = jsonData.yyjzsj
                                    }
                                },
                                assignedPerson = new assignedPerson
                                {
                                    classCode = "ASSIGNED",
                                    id1 = new id1 { root = "2.16.156.10011.1.4", extension = jsonData.empid }
                                }
                            },
                            arrivedBy = new arrivedBy
                            {
                                transportationIntent = new transportationIntent
                                {
                                    moodCode = "PRP",
                                    id1 = new id1 { root = "2.16.156.10011.2.5.1.20", extension = "" },
                                    code = new code(),
                                    effectiveTime = new effectiveTime
                                    {
                                        low1 = new low1
                                        {
                                            value = jsonData.kssj
                                        },
                                        high = new high
                                        {
                                            value = jsonData.jssj
                                        }
                                    }
                                }
                            },
                            extension = new extension
                            {
                                dotype = new value { value1 = jsonData.dotype },
                                sjly = new value { value1 = jsonData.sjly },
                                lyxt = new value { value1 = jsonData.lyxt },
                                hoscode = new value { value1 = jsonData.hoscode },
                                yyid = new value { value1 = jsonData.yyid },
                                pbid = new value { value1 = jsonData.pbid },
                                mrn = new value { value1 = jsonData.mrn },
                                pname = new value { value1 = jsonData.pname },
                                pcid = new value { value1 = jsonData.pcid },
                                yyjzsj = new value { value1 = jsonData.yyjzsj },
                                deptid = new value { value1 = jsonData.deptid },
                                classid = new value { value1 = jsonData.classid },
                                fsdzylx = new value { value1 = jsonData.fsdzylx },
                                empid = new value { value1 = jsonData.empid },
                                kssj = new value { value1 = jsonData.kssj },
                                jssj = new value { value1 = jsonData.jssj },
                                yyztdm = new value { value1 = jsonData.yyztdm },
                                yyztmc = new value { value1 = jsonData.yyztmc },
                                useflag = new value { value1 = jsonData.useflag },
                                in_empid = new value { value1 = jsonData.in_empid },
                                in_date = new value { value1 = jsonData.in_date },
                                xg_empid = new value { value1 = jsonData.xg_empid },
                                xgsj = new value { value1 = jsonData.xgsj }
                            }
                        }
                    }
                }
            };

            hl7Xml = HL7V3Helper.SerializeToXml(xmlRoot);

            return hl7Xml;
        }
    }
}
